package net.xiangcaowuyu.mybatisplussample.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.xiangcaowuyu.mybatisplussample.domain.User;
import net.xiangcaowuyu.mybatisplussample.mapper.UserMapper;
import net.xiangcaowuyu.mybatisplussample.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description:
 *
 * @author : laughing
 * DateTime: 2021-04-22 9:26
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private IUserService userService;

    @GetMapping("list")
    public List<User> list() {
        return userService.list();
    }

    @GetMapping("list1")
    public List<User> list1() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 1).or().eq("name", "Tom");
        return userService.list(queryWrapper);
    }

    @GetMapping("page")
    public Page<User> page() {
        IPage<User> userPage = new Page<>(1, 3);
        return userService.selectUserList(userPage);
    }

    @GetMapping(value = "listTenant")
    public List<User> listTenant() {
        return userService.selectUserTenant();
    }

    @GetMapping("logicdelete/{id}")
    public Boolean logicdelete(@PathVariable("id") Long id) {
        return userService.removeById(id);
    }

    @GetMapping("add")
    public Boolean addUser() {
        User user = new User();
        user.setName("张三");
        user.setAge(30);
        return userService.save(user);
    }
}
